package server

import (
	"net/http"

	"git.oschina.net/dddailing/drsys/backend/model"
)

func (app *App) SetRouter(mux *http.ServeMux) {
	mux.Handle("/", http.RedirectHandler("/static/index.html", 302))

	mux.Handle("/static/",
		http.StripPrefix("/static/",
			http.FileServer(http.Dir("static"))))

	mux.HandleFunc("/api/add_patient",
		HandleJsonReq(
			app.RequireToken,
			ReadBody,
			BodyToJson,
			app.HandleAddPatient,
		))

	mux.HandleFunc("/api/upload",
		HandleJsonReq(
			app.RequireToken,
			app.HandleUploadPic,
		))

	mux.HandleFunc("/api/get_single_image/",
		HandleJsonReq(
			// app.RequireToken,
			app.HandleGetSingleImage,
		))

	mux.HandleFunc("/api/get_single_image_eng/",
		HandleJsonReq(
			app.RequireToken,
			app.HandleGetSingleImageEng,
		))

	mux.HandleFunc("/api/get_image_list",
		HandleJsonReq(
			app.RequireToken,
			app.HandleGetImageList,
		))

	mux.HandleFunc("/api/get_user_ele",
		HandleJsonReq(
			app.RequireToken,
			app.HandleGetUI,
		))

	mux.HandleFunc("/api/dr_grade_no_limit",
		HandleJsonReq(
			ReadBody,
			BodyToJson,
			app.Diagnose,
		))

	mux.HandleFunc("/api/dr_grade_no_limit2",
		HandleJsonReq(
			ReadBody,
			BodyToJson,
			app.HandleGetClassification2,
		))

	mux.HandleFunc("/1.0/dp/dr",
		HandleJsonReq(
			app.LimitAPI(100),
			ReadBody,
			BodyToJson,
			app.Diagnose,
		))

	mux.HandleFunc("/api/get_report/",
		HandleJsonReq(
			app.HandleGetReport,
		))

	mux.HandleFunc("/api/quality_assessment",
		HandleJsonReq(
			app.RequireToken,
			ReadBody,
			app.HandleGetQuality,
		))

	mux.HandleFunc("/1.0/dp/marker",
		HandleJsonReq(
			ReadBody,
			BodyToJson,
			app.RequireToken,
			app.HandleDeepMarker,
		))

	mux.HandleFunc("/api/update_user_profile",
		HandleJsonReq(
			app.RequireToken,
			BodyToObj(new(model.User)),
			app.HandleUpdateUserProfile,
		))

	mux.HandleFunc("/api/get_user_profile",
		HandleJsonReq(
			app.RequireToken,
			app.HandleGetUserProfile,
		))

	mux.HandleFunc("/api/get_token",
		HandleJsonReq(
			ReadBody,
			BodyToObj(new(model.User)),
			app.HandleToken,
		))

	// Binary Obj
	mux.HandleFunc("/api/insert_binary_object",
		HandleJsonReq(
			app.RequireToken,
			app.HandleInsertBinaryObject,
		))

	mux.Handle("/binobject/get/",
		http.StripPrefix("/binobject/get/",
			HandleJsonReq(
				// app.RequireToken,
				app.HandleGetBinaryObject,
			)))

	mux.Handle("/api/limit_test",
		HandleJsonReq(
			app.LimitAPI(10),
			app.HandleLimitTest,
		))

	mux.Handle("/api/manger/add_user",
		HandleJsonReq(
			app.RequireToken,
			app.LimitUserAccessLevel(100),
			ReadBody,
			BodyToObj(new(model.User)),
			app.HandleAddUser,
		))

	mux.Handle("/api/task_call_demo",
		HandleJsonReq(
			ReadBody,
			BodyToJson,
			app.CallTasks("demo"),
		))

	mux.Handle("/api/enhance",
		HandleJsonReq(
			ReadBody,
			BodyToJson,
			app.CallTasksWithRawResponse("enhance"),
		))

}
